package com.woniu.smallmedical.controller;

import com.woniu.smallmedical.entity.PatientInformation;
import com.woniu.smallmedical.entity.Registration;
import com.woniu.smallmedical.entity.ResponseResult;
import com.woniu.smallmedical.server.PatientInformationServer;
import com.woniu.smallmedical.server.PhysiqueServer;
import com.woniu.smallmedical.server.RegistrationServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class RegistrationController {
    @Autowired
    RegistrationServer registrationServer;
    @Autowired
    PatientInformationServer patientInformationServer;
    @Autowired
    PhysiqueServer physiqueServer;


    @PostMapping("/addRegistration")
    public ResponseResult AddRegistration(@RequestBody Registration registration) {
        System.out.println("挂号表！！！！" + registration);
        PatientInformation p = patientInformationServer.getPatByPatnum(registration.getSickid());
        Registration r = new Registration();
        r.setBillnum(registration.getBillnum());
        r.setSickid(p.getPaid());
        r.setRtime(registration.getRtime());
        r.setDepartmentid(registration.getDepartmentid());
        r.setReceptiontypeid(registration.getReceptiontypeid());
        r.setDoctorid(registration.getDoctorid());
        r.setRegistrationtypeid(registration.getRegistrationtypeid());
        r.setRegistrarid(registration.getRegistrarid());
        r.setPhysiqueid(physiqueServer.getPhysiqueByPaid(p.getPaid()).getPid());
        System.out.println("===挂号信息===" + r);
        registrationServer.AddRegistration(r);
        return new ResponseResult(null, 200, "增加挂号表！");
    }

    //查询患者信息和挂号信息还有科室，医生
    @GetMapping("/registrations")
    public ResponseResult registrations(@RequestBody Registration registration,
                                        String startTime, String endTime,
                                        String patientname) {
        System.out.println("挂号单信息======" + registration);
        System.out.println("起始时间======" + startTime);
        System.out.println("结束时间======" + endTime);
        System.out.println("患者姓名======" + patientname);
        return new ResponseResult(null, 200, "查询成功！");
    }

    //通过患者id查询挂号信息
    @GetMapping("/getBySickid/{sickid}")
    public ResponseResult getBySickid(@PathVariable int sickid) {
        Registration bySickid = registrationServer.getBySickid(sickid);
        return new ResponseResult(bySickid, 200, "通过患者id查询挂号信息！");
    }

    //通过患者的id来修改挂号表信息
    @PutMapping("/updateBySickid/{sickid}")
    public ResponseResult updateBySickid(@PathVariable int sickid,
                                         @RequestBody Registration registration) {
        System.out.println("修改信息==========="+registration);
        registrationServer.updateBySickid(sickid,registration);
        return new ResponseResult(null, 200, "通过患者id修改了挂号信息！");
    }
}
